package cn.tedu.service.impl;

import cn.tedu.mapper.CollectMapper;
import cn.tedu.pojo.Collect;
import cn.tedu.service.CollectService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectMapper collectMapper;

    @Override
    public void addNovel(Collect collect) {
        //todo 此处前端应加判断，防止重复添加
        collectMapper.insert(collect);
    }

    @Override
    public void deleteNovel(Collect collect) {
        QueryWrapper<Collect> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("user_id", collect.getUserId())
                    .eq("novel_id", collect.getNovelId());
        collectMapper.delete(queryWrapper);
    }
}
